package com.example.myapplication.slice;

import com.example.common.base.BaseAbilitySlice;
import com.example.myapplication.ResourceTable;
import com.jdd966.navigation.NavigationTab;
import com.jdd966.navigation.NavigationTabClickListener;
import com.jdd966.navigation.NavigationTabList;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.utils.Color;

import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT;
import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_PARENT;

/**
 * @author geyao
 * @date 2021/7/13
 * des:
 */
public class MainAbilitySlice extends BaseAbilitySlice {
    private NavigationTabList tabTemp;
    private NavigationTabList tabTemp2;
    private Button btn;
    private Button btn2;

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        btn = (Button) findComponentById(ResourceTable.Id_btn_click);
        btn.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                tabTemp.setFixedMode(!tabTemp.getFixedMode());
                btn.setText(String.valueOf(tabTemp.getFixedMode()));
            }
        });
        btn2 = (Button) findComponentById(ResourceTable.Id_btn_click2);
        btn2.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                tabTemp2.setFixedMode(!tabTemp2.getFixedMode());
                btn2.setText(String.valueOf(tabTemp2.getFixedMode()));
            }
        });
        initComponent1();
        initComponent2();
        initComponent3();
        initComponent4();
        btn.setText(String.valueOf(tabTemp.getFixedMode()));
        btn2.setText(String.valueOf(tabTemp2.getFixedMode()));
    }

    private void initComponent1() {
        tabTemp = (NavigationTabList) findComponentById(ResourceTable.Id_tbl_list1);
        tabTemp.setFixedMode(true);
        tabTemp.addTab(
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_service_normal)
                        .setSelectedImage(ResourceTable.Media_ic_service_selected)
                        .setText("首页")
                        .setTabSelected(true)
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setImageScaleMode(Image.ScaleMode.CLIP_CENTER)
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_TOP_TEXT_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_icbc_normal)
                        .setSelectedImage(ResourceTable.Media_ic_icbc_selected)
                        .setText("工银e钱包")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_TOP_TEXT_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_find_normal)
                        .setSelectedImage(ResourceTable.Media_ic_find_selected)
                        .setText("发现")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_TOP_TEXT_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_mine_normal)
                        .setSelectedImage(ResourceTable.Media_ic_mine_selected)
                        .setText("我的")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_TOP_TEXT_BOTTOM));
        tabTemp.setOnTabClickListener(new NavigationTabClickListener() {
            @Override
            public void onTabClicked(int position) {
                btn.setText("position: " + position);
            }
        });
    }

    private void initComponent2() {
        NavigationTabList tabList = (NavigationTabList) findComponentById(ResourceTable.Id_tbl_list2);
        tabList.addTab(
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_service_normal)
                        .setSelectedImage(ResourceTable.Media_ic_service_selected)
                        .setImageSize(150, 150)
                        .setText("首页")
                        .setTabSelected(true)
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setImageScaleMode(Image.ScaleMode.CLIP_CENTER)
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_TOP_TEXT_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_icbc_normal)
                        .setSelectedImage(ResourceTable.Media_ic_icbc_selected)
                        .setText("工银e钱包")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.TEXT_TOP_IMAGE_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_find_normal)
                        .setSelectedImage(ResourceTable.Media_ic_find_selected)
                        .setText("发现")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_LEFT_TEXT_RIGHT),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_mine_normal)
                        .setSelectedImage(ResourceTable.Media_ic_mine_selected)
                        .setText("我的")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.TEXT_LEFT_IMAGE_RIGHT),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_service_normal)
                        .setSelectedImage(ResourceTable.Media_ic_service_selected)
                        .setText("首页")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setImageScaleMode(Image.ScaleMode.CLIP_CENTER)
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_TOP_TEXT_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_icbc_normal)
                        .setSelectedImage(ResourceTable.Media_ic_icbc_selected)
                        .setText("工银e钱包")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.TEXT_TOP_IMAGE_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_find_normal)
                        .setSelectedImage(ResourceTable.Media_ic_find_selected)
                        .setText("发现")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_LEFT_TEXT_RIGHT),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_mine_normal)
                        .setSelectedImage(ResourceTable.Media_ic_mine_selected)
                        .setText("我的")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.TEXT_LEFT_IMAGE_RIGHT),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_find_normal)
                        .setSelectedImage(ResourceTable.Media_ic_find_selected)
                        .setText("发现")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_LEFT_TEXT_RIGHT),
                new NavigationTab(this)
                        .setTabSize(MATCH_CONTENT, MATCH_PARENT)
                        .setImage(ResourceTable.Media_ic_mine_normal)
                        .setSelectedImage(ResourceTable.Media_ic_mine_selected)
                        .setText("我的")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.TEXT_LEFT_IMAGE_RIGHT));
        tabList.setOnTabClickListener(new NavigationTabClickListener() {
            @Override
            public void onTabClicked(int position) {
                btn.setText("position: " + position);
            }
        });
    }

    private void initComponent3() {
        tabTemp2 = (NavigationTabList) findComponentById(ResourceTable.Id_tbl_list3);
        tabTemp2.addTab(
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_service_normal)
                        .setSelectedImage(ResourceTable.Media_ic_service_selected)
                        .setImageSize(150, 150)
                        .setText("首页")
                        .setTabSelected(true)
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setImageScaleMode(Image.ScaleMode.CLIP_CENTER)
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_TOP_TEXT_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_icbc_normal)
                        .setSelectedImage(ResourceTable.Media_ic_icbc_selected)
                        .setText("工银e钱包")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.TEXT_TOP_IMAGE_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_find_normal)
                        .setSelectedImage(ResourceTable.Media_ic_find_selected)
                        .setText("发现")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_LEFT_TEXT_RIGHT),
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_mine_normal)
                        .setSelectedImage(ResourceTable.Media_ic_mine_selected)
                        .setText("我的")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.TEXT_LEFT_IMAGE_RIGHT));
        tabTemp2.setOnTabClickListener(new NavigationTabClickListener() {
            @Override
            public void onTabClicked(int position) {
                btn2.setText("position: " + position);
            }
        });
    }

    private void initComponent4() {
        NavigationTabList tabList = (NavigationTabList) findComponentById(ResourceTable.Id_tbl_list4);
        tabList.addTab(
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_service_normal)
                        .setSelectedImage(ResourceTable.Media_ic_service_selected)
                        .setImageSize(150, 150)
                        .setText("首页")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setImageScaleMode(Image.ScaleMode.CLIP_CENTER)
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_TOP_TEXT_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_icbc_normal)
                        .setSelectedImage(ResourceTable.Media_ic_icbc_selected)
                        .setText("工银e钱包")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.TEXT_TOP_IMAGE_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_find_normal)
                        .setSelectedImage(ResourceTable.Media_ic_find_selected)
                        .setText("发现")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_LEFT_TEXT_RIGHT),
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_mine_normal)
                        .setSelectedImage(ResourceTable.Media_ic_mine_selected)
                        .setText("我的")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.TEXT_LEFT_IMAGE_RIGHT),
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_service_normal)
                        .setSelectedImage(ResourceTable.Media_ic_service_selected)
                        .setImageSize(150, 150)
                        .setText("首页")
                        .setTabSelected(true)
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setImageScaleMode(Image.ScaleMode.CLIP_CENTER)
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_TOP_TEXT_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_icbc_normal)
                        .setSelectedImage(ResourceTable.Media_ic_icbc_selected)
                        .setText("工银e钱包")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.TEXT_TOP_IMAGE_BOTTOM),
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_find_normal)
                        .setSelectedImage(ResourceTable.Media_ic_find_selected)
                        .setText("发现")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.IMAGE_LEFT_TEXT_RIGHT),
                new NavigationTab(this)
                        .setTabSize(MATCH_PARENT, MATCH_CONTENT)
                        .setImage(ResourceTable.Media_ic_mine_normal)
                        .setSelectedImage(ResourceTable.Media_ic_mine_selected)
                        .setText("我的")
                        .setTextSize(50)
                        .setTextColor(Color.BLACK)
                        .setTextSelectedColor(new Color(0xFFFBA123))
                        .setDistance(15)
                        .build(NavigationTab.BuildType.TEXT_LEFT_IMAGE_RIGHT));
        tabList.setOnTabClickListener(new NavigationTabClickListener() {
            @Override
            public void onTabClicked(int position) {
                btn2.setText("position: " + position);
            }
        });
    }
}
